﻿using Shop.Data.Entities;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
//La tabla Factura esta echo por Roger ticona nina
namespace Shop.Data.Business
{
    public class FacturaBusiness
    {
        public static IList<Factura> GetListByFilter(string filter)
        {
            using (ShopDbContext ctx = new ShopDbContext())
            {
                return ctx.Facturas.Where(t => t.DniCliente.Contains(filter)).ToList();
            }


        }

        public static Factura Create(Factura factura)
        {
            using (ShopDbContext ctx = new ShopDbContext())
            {
                Factura facturaDB = ctx.Facturas.Add(factura);
                ctx.SaveChanges();
                return facturaDB;
            }
        }
        public static Factura Update(Factura factura)
        {
            using (ShopDbContext ctx = new ShopDbContext())
            {

                ctx.Entry(factura).State = EntityState.Modified;
                ctx.SaveChanges();
                return factura;

            }
        }
        public static Factura GetById(Guid id)
        {

            using (ShopDbContext ctx = new ShopDbContext())
            {

                Factura p = ctx.Facturas.Find(id);
                if (p == null)
                {
                    throw new Exception("Cliente GetById Not");
                }
                return p;
            }

        }

        public static void Delete(Guid IdFactura)
        {

            using (ShopDbContext ctx = new ShopDbContext())
            {
                Factura p = ctx.Facturas.Find(IdFactura);

                if (p == null)
                {
                    throw new Exception("Cliente no Tiene Data");

                }
                ctx.Facturas.Remove(p);
                ctx.SaveChanges();

            }
        }


    }
}
